﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HairFacebookApp.DAO
{
    public class FileUtil
    {
        /**
         * Write only some strings in an array to a file.
         * Use to log exception
         **/
        public static void WriteToFile(string filePath, string text, bool appendFlg)
        {            
            StreamWriter file = new System.IO.StreamWriter(filePath, appendFlg);
            //add date time to the text
            file.WriteLine(DateTime.Now.ToShortDateString() + ":" + text + "\n");
            file.Flush();
            file.Close();
        }

        public static string BuildFilePath(string folderPath, string fileName)
        {
            try
            {
                if (!folderPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    return folderPath + Path.DirectorySeparatorChar + fileName;
                }
                else
                {
                    return folderPath + fileName;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error while writing file '" + fileName + "'" + ex.Message);
            }

        }
    }
}
